// pages/evaluate/evaluate.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    identity: null,
    info: {},
    optionList: ['punctual', 'skill', 'efficiency', 'responsibility'],
    punctualFraction: 0,
    skillFraction: 0,
    efficiencyFraction: 0,
    responsibilityFraction: 0,
    content: ''
  },

  // 评分
  scoring: function (e) {
    // console.log(e.detail.fraction)
    let optionsList = this.data.optionList
    optionsList.map(item => {
      const child = this.selectComponent(`#${item}`);
      // console.log(child.data.number)
      let key = `${item}Fraction`
      this.setData({
        [key]: child.data.number
      })
    })
  },

  // 评价内容
  saveContent: function (e) {
    this.setData({
      content: e.detail.value
    })
  },

  // 发布评价
  release: function () {
    wx.showLoading({
      title: '正在提交...',
      mask: true
    })
    if (wx.getStorageSync('identity') == 1) {
      app.post('Member/saveEvaluate', {
        we_work_id: this.data.info.w_id,
        we_args1: this.data.punctualFraction,
        we_args2: this.data.skillFraction,
        we_args3: this.data.efficiencyFraction,
        we_args4: this.data.responsibilityFraction,
        we_content: this.data.content
      }).then(res => {
        wx.hideLoading()
        wx.showToast({
          title: '评价成功',
          mask: true
        })
        setTimeout(() => {
          wx.navigateBack({
            delta: 1,
          })
        }, 1000);
      })
    } else {
      app.post('Work/saveEvaluate', {
        id: this.data.info.c_id,
        args1: this.data.punctualFraction,
        args2: this.data.skillFraction,
        args3: this.data.efficiencyFraction,
        args4: this.data.responsibilityFraction,
        content: this.data.content
      }).then(res => {
        wx.hideLoading()
        wx.showToast({
          title: '评价成功',
          mask: true
        })
        wx.navigateBack({
          delta: 1,
        })
      })
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      identity: wx.getStorageSync('identity')
    })
    if (wx.getStorageSync('identity') == 1) {
      app.post('Member/showEvaluate', {
        id: options.id
      }).then(res => {
        this.setData({
          info: res.data.result_data
        })
      })
    } else {
      app.post('Work/showEvaluate', {
        id: options.id
      }).then(res => {
        this.setData({
          info: res.data.result_data
        })
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})